<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\dao\car;

use app\dao\BaseDao;
use app\model\car\CarService;

class CarServiceDao extends BaseDao
{
    protected function setModel(): string
    {
        // TODO: Implement setModel() method.
        return CarService::class;
    }

    /**
     * @param array $where
     * @param string $field
     * @param int $page
     * @param int $limit
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 获取列表
     */
    public function getList(array $where=[],string $field = '*',int $page = 0,int $limit = 0) {
        $model = $this->getModel()->field($field)->where('is_del',0);
        if($where['status']!="") {
            $model->where('status', $where['status']);
        }
        if(!empty($where['keyword'])) {
            $model->where('name','like','%'.$where['keyword'].'%');
        }
        $count = $model->order('add_time DESC')->count();
        $list = $model->order('add_time DESC')->page($page, $limit)->select()->toArray();

        return compact('count','list');
    }

    /**
     * 删除
     * @param int $id
     * @return array
     */
    public function del (int $id) {
        $del = $this->getModel()->where('id',$id)->useSoftDelete('delete_time',time())->delete();
        $this->getModel()->where('id',$id)->useSoftDelete('is_del',1)->delete();
        return ['删除成功',$del];
    }
}
